<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login extends MY_Controller {
    /**
     * the class's construct function
     */
    public function __construct(){
        parent::__construct();
    }

    public function index()
    {
        $data['error'] = "";
        $this->load->library('form_validation');
        $this->load->helper('url');
        $this->load->view("login/login.html",$data);
    }
    /**
     * Login controller function
     */
    public function login(){
        $account =  ($this->input->post('account')) ? html_escape($this->input->post('account')) : "";
        $password = ($this->input->post('pw')) ? html_escape($this->input->post('pw')) : "";

        $this->load->helper('url');

        if (empty($account) || empty($password)){
            $data['error'] = "用户名或密码错误";
            $this->load->view("login/login.html", $data);
            return false;
        }

        if($account != USER_ADMIN || $password != USER_PWD) {
            $data['error'] = "用户名或密码错误";
            $this->load->view("login/login.html", $data);
            return false;
        }

        $this->session->set_userdata('upfile_account', $account);
        $this->session->set_userdata('upfile_pw', md5($password));


        redirect('version/uploadfile');
        exit();
    }
    public function logout() {
        $this->load->helper('url');
        $this->session->sess_destroy();
        redirect('login/index');
    }
}
